<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script type="module">
    import { ajax, get, post, getJSON } from './index.js'
    let url = 'https://www.imooc.com/api/http/search/suggest?word=js'
    // let url = 'https://www.imooc.com/api/http/json/search/suggest?word=js'
    // let url = '/xxx'

    // const xhr = ajax(url, {
    //   method: 'post',
    //   // timeoutTime:10,
    //   params: {
    //     tv: 'r20210812',
    //     st: 'env',
    //   },
    //   data: {
    //     username: '2423',
    //     age: 234
    //   },
    //   cotentType:'application/json', // 服务器端允许才能发该请求
    //   responseType:'json',
    //   success(data, xhr) {
    //     console.log('success')
    //     console.log(data)
    //     console.log(xhr)
    //   },
    //   abort(xhr) {
    //     console.log('abort')
    //     console.log(xhr)
    //   },
    //   timeout(xhr) {
    //     console.log('timeout')
    //     console.log(xhr)
    //   },
    //   error(xhr) {
    //     console.log('error')
    //     console.log(xhr)
    //   },
    //   httpCodeError(status, xhr) {
    //     console.log('httpCodeError')
    //     console.log(status)
    //     console.log(xhr)
    //   },
    // })


    // xhr.abort()


    let p = ajax(url, {
      params: { age: 18 },
      responseType: 'json',
      // timeoutTime: 10
    })
    // p.xhr.abort()
    console.log(p.ERROR_ABORT_TEXT)
    p.then(res => {
      console.log(res)
    }).catch(err => {
      console.log(err)
    })
  </script>
</body>

</html>